package com.klikmee.sms.chat.web.dao;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import com.klikmee.sms.services.chat.model.Agent;
import com.klikmee.sms.services.chat.model.Group;

public class GroupDAO extends AbstractDAO<Group> {

	public GroupDAO() {
		super(Group.class);
	}

	@PersistenceContext
	private EntityManager em;

	@SuppressWarnings("unchecked")
	public List<Group> selectAll() {
		List<Group> groups = null;
		try {
			groups = (List<Group>) em.createNamedQuery("Group.findAll").getResultList();
		} catch (NoResultException e) {

		}

		return groups;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> selectAllGroupsForAgent(Agent agent) {
		List<Object> groups = null;
		try {
			groups = (List<Object>) em.createNamedQuery("Group.findAllGroupsForAgent").setParameter("agent", agent).getResultList();
		} catch (NoResultException e) {

		}

		return groups;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> selectAdministrationGroupsForAgent(Agent agent) {
		List<Object> groups = null;
		try {
			groups = (List<Object>) em.createNamedQuery("Group.findAdministratorGroupsForAgent").setParameter("agent", agent).getResultList();
		} catch (NoResultException e) {

		}

		return groups;
	}
}